<?php

namespace models;

class Praise {
		
	/** 添加 **/
	public static function add($db, $userId, $type, $sourceId) {
	    $sql = "INSERT INTO t_praise(userId, type, sourceId, createdAt, modifiedAt, isDeleted) VALUES(?,?,?,?,?,?)";
	    $data = $db->executeUpdate($sql, array($userId, $type, $sourceId, time(), time(), false));
	    return $data;
    }

    /** 删除 **/
	public static function remove($db, $userId, $type, $sourceId) {
        $sql = "DELETE FROM t_praise WHERE userId =? AND type=? AND sourceId=?";
	    $data = $db->executeUpdate($sql, array($userId, $type, $sourceId));
	    return $data;
    }

    /** 通过uid menuid获取点赞 **/
	public static function getByUidMid($db, $userId, $type, $sourceId) {
        $sql = "SELECT * FROM t_praise WHERE isDeleted = 0 AND type=$type AND userId =? AND sourceId=?";
	    $data = $db->fetchAssoc($sql, array($userId, $sourceId));
	    return $data;
    }
}

